﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using YhmOA.Model;
using Microsoft.Data.Extensions;

namespace YhmOA.EFDAL
{
    public partial class Entities : ObjectContext
    {
        #region 调整顶部菜单的顺序
        /// <summary>
        /// 调整顶部菜单的顺序
        /// </summary>
        /// <param name="ID">要调整的ID</param>
        /// <param name="BeforeOrAfter">向前还是向后（1标示向前，0标示向后）</param>
        public void TopMenuOrder(int ID, int BeforeOrAfter)
        {
            System.Data.SqlClient.SqlParameter[] sqlparams = new System.Data.SqlClient.SqlParameter[]{
                new System.Data.SqlClient.SqlParameter { ParameterName = "ID", DbType = System.Data.DbType.Int32, Value = ID },
                new System.Data.SqlClient.SqlParameter { ParameterName = "BeforeOrAfter", DbType = System.Data.DbType.Int32, Value = BeforeOrAfter }
            };

            System.Data.Common.DbCommand command = this.CreateStoreCommand("P_ManagerOA_Menu_TopMenu_UpdateShowOrder", System.Data.CommandType.StoredProcedure, sqlparams);
            using (command.Connection.CreateConnectionScope())
            command.ExecuteNonQuery();
        }
        #endregion

        #region 维护顶部菜单时获取左边菜单的方法
        /// <summary>
        /// 维护顶部菜单时获取左边菜单的方法
        /// </summary>
        /// <param name="ID">顶部菜单的ID</param>
        /// <param name="SearchText">查询关键字</param>
        /// <returns></returns>
        public List<ManagerOA_Menu_LeftMenu> GetManagerOA_Menu_LeftMenuByTopMenuID(int ID,string SearchText)
        {
            List<ManagerOA_Menu_LeftMenu> list = new List<ManagerOA_Menu_LeftMenu>();
            Materializer<ManagerOA_Menu_LeftMenu> listMaterializer = new Materializer<ManagerOA_Menu_LeftMenu>();
            System.Data.SqlClient.SqlParameter[] sqlparams = new System.Data.SqlClient.SqlParameter[]{
                new System.Data.SqlClient.SqlParameter { ParameterName = "ID", DbType = System.Data.DbType.Int32, Value = ID },
                new System.Data.SqlClient.SqlParameter { ParameterName = "search", DbType = System.Data.DbType.String, Value = SearchText }
            };

            System.Data.Common.DbCommand command = this.CreateStoreCommand("P_ManagerOA_Menu_Search_NotTop_Left", System.Data.CommandType.StoredProcedure, sqlparams);
            using (command.Connection.CreateConnectionScope())
                list = listMaterializer.Materialize(command).ToList();
            return list;
        }
        #endregion

        #region 顶部菜单管理
        /// <summary>
        /// 顶部菜单管理
        /// </summary>
        public ObjectSet<ManagerOA_Menu_TopMenu> ManagerOA_Menu_TopMenu
        {
            get
            {
                if ((_ManagerOA_Menu_TopMenu == null))
                {
                    _ManagerOA_Menu_TopMenu = base.CreateObjectSet<ManagerOA_Menu_TopMenu>("ManagerOA_Menu_TopMenu");
                }
                return _ManagerOA_Menu_TopMenu;
            }
        }
        private ObjectSet<ManagerOA_Menu_TopMenu> _ManagerOA_Menu_TopMenu;
        #endregion

        #region 左边菜单管理
        /// <summary>
        /// 左边菜单管理
        /// </summary>
        public ObjectSet<ManagerOA_Menu_LeftMenu> ManagerOA_Menu_LeftMenu
        {
            get
            {
                if ((_ManagerOA_Menu_LeftMenu == null))
                {
                    _ManagerOA_Menu_LeftMenu = base.CreateObjectSet<ManagerOA_Menu_LeftMenu>("ManagerOA_Menu_LeftMenu");
                }
                return _ManagerOA_Menu_LeftMenu;
            }
        }
        private ObjectSet<ManagerOA_Menu_LeftMenu> _ManagerOA_Menu_LeftMenu;
        #endregion
    }
}
